<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>XMS AE-API</title>
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/global.css">
<link href="/css/font-awesome.min.css" rel="stylesheet">
<link href="/css/jquery-confirm.min.css" rel='stylesheet' type='text/css' />
<script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
<script src="/js/jquery-confirm.min.js"></script>
<script src="/js/common.js"></script>
</head>
<body>
	<%@include file="inc/menu-nav.jsp" %>
	<div class="container">
		<h3 class="head-title">
			<c:choose>
				<c:when test="${productMapping != null}">
					编辑产品映射
				</c:when>
				<c:otherwise>
					添加产品映射
				</c:otherwise>
			</c:choose>
		</h3>
		<form class="form-horizontal form-group product-mapping-form" method="post">
			<c:choose>
				<c:when test="${productMapping != null}">
					<input type="hidden" id="type" value="1">
				</c:when>
				<c:otherwise>
					<input type="hidden" id="type" value="0">
				</c:otherwise>
			</c:choose>
			<div class="form-group">
				<label for="pk_code_shipper" class="col-sm-2 control-label">菜鸟代码：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" name="pk_code_shipper" value="${productMapping.pk_code_shipper }" id="pk_code_shipper" maxlength="30" required="required" autofocus="autofocus">
				</div>
				<label for="pk_name_shipper" class="col-sm-2 control-label">产品名称：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" name="pk_name_shipper" value="${productMapping.pk_name_shipper }" id="pk_name_shipper" maxlength="30" required="required">
				</div>
			</div>
			<div class="form-group">
				<label for="pk_code" class="col-sm-2 control-label">产品代码：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control text-uppercase" name="pk_code" value="${productMapping.pk_code }" id="pk_code" maxlength="2" required="required">
				</div>
				<label for="hawbcode_format" class="col-sm-2 control-label">单号格式：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" name="hawbcode_format" value="${productMapping.hawbcode_format }" id="hawbcode_format" maxlength="30" placeholder="正则表达式格式">
				</div>
			</div>
			<div class="form-group">
				<label for="max_price_limit" class="col-sm-2 control-label">申报价限制：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" name="max_price_limit" value="${productMapping.max_price_limit }" id="max_price_limit" placeholder="单位：$">
				</div>
				<label class="col-sm-2 control-label">是否允许带电：</label>
				<div class="col-sm-4">
					<label class="radio-inline">
						<input type="radio" name="is_battery" required="required" <c:if test="${productMapping.is_battery == 'Y' }"> checked="checked" </c:if> value="Y"> 是
					</label>
					<label class="radio-inline">
						<input type="radio" name="is_battery" required="required" <c:if test="${productMapping.is_battery == 'N' }"> checked="checked" </c:if> value="N"> 否
					</label>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-2"></div>
				<div class="col-sm-4">
					<button type="submit" class="btn btn-danger"> 提交 </button>
				</div>
			</div>
		</form>
	</div>
</body>
<script type="text/javascript">
	$(function(){
		$('.product-mapping-form').on('submit', function(){
			var param = {
				pk_code_shipper: $('#pk_code_shipper').val(),
				pk_code: $('#pk_code').val(),
				hawbcode_format: $('#hawbcode_format').val(),
				max_price_limit: $('#max_price_limit').val(),
				pk_name_shipper: $('#pk_name_shipper').val(),
				type: $('#type').val(),
				is_battery: $('input[name="is_battery"]:checked').val()
			};
			var tips = Tips.tips('<i class="icon-spinner icon-spin ext-spinner"></i> 正在保存数据，请稍候...');
			$.post('/product/mapping/save', param, function(result){
				tips.close();
				if(result.status == 0){
	        		content = '<i class="icon-error icon-remove-sign"></i> ' + result.msg;
	        	}else{
	        		content = '<i class="icon-success icon-ok-sign"></i> ' + result.msg;
	        	}
	        	Tips.tips(content, function(){
	        		location = '/product/mapping/index';
	        	});
			});
			return false;
		});
	});
</script>
</html>